//Api管理
import{storageX} from "@/common/StorageX";
const storageObj = storageX();
// export const baseUrl = 'http://192.168.0.61:8000/';
export const baseUrl = 'https://project.src-code.com.cn:8685/api';
//发起请求
export function getRequest(method="get",url,data,token){
	let request;
	switch(method){
	    case "get":
			request = uni.request({
				url: baseUrl+url,
				method:'GET',
				header: {
					'content-type': 'application/json', //自定义请求头信息
					'ssid':token || '',
				},
				data:data,
			});
			break;
		case "post":
			request = uni.request({
				url: baseUrl+url,
				method:'POST',
				header: {
					'content-type': 'application/json', //自定义请求头信息
					'ssid':token || '',
				},
				data:data,
			});
			break;
		case "delete":
			request = uni.request({
				url: baseUrl+url,
				method:'DELETE',
				header: {
					'content-type': 'application/json', //自定义请求头信息
					'ssid':token || '',
				},
				data:data,
			});
			break;
	}
	return request.then(([error,response]) => {
		if(error){  //请求发生错误
			return Promise.reject(error);
		}
		if(response.data.state == 200){
			return response;
		}else if(response.data.state == 201){
			uni.navigateTo({
				url:'/pages/login/login',
			});
		}else if(response.data.state == 403){
			uni.showToast({
				title: '您没有该权限',
				duration: 2000,
			});
		}
		return Promise.reject(response);
	});
};

//所有API
/**
登陆管理
**/
//获取用户登陆状态
export function getLoginState(){
    return getRequest(
        'get',
        '/login',
        {},
		storageObj.token,
    );
}
//用户登陆
export function login(data){
    return getRequest(
        'post',
        '/2/login',
        data,
		storageObj.token,
    );
}
/**
问题管理
**/
//获取问题详情
export function getProblemInfoById(id){
    return getRequest(
        'get',
        '/wx/quest/'+id,
        {},
		storageObj.token,
    );
}
/**
搜索管理
**/
//获取搜索分类
export function getSearchTypes(){
    return getRequest(
        'get',
        '/wx/quest/',
        {},
		storageObj.token,
    );
}
/**
项目管理
**/
//项目标签点击
export function getProjectInfo(params){
    return getRequest(
        'post',
        '/wx/project/get',
        params,
		storageObj.token,
    );
}
/**
月度汇总
**/
export function deleteSummary(id){  //根据id删除月度汇总数据
    return getRequest(
        'delete',
        '/wx/summary/delete/'+id,
        {},
		storageObj.token,
    );
}
export function getSummary(id){  //根据id获取月度汇总数据
    return getRequest(
        'post',
        '/wx/summary/get/'+id,
        {},
		storageObj.token,
    );
}
export function findSummarys(params){  //查询月度汇总列表
    return getRequest(
        'get',
        '/wx/summary/list',
        params,
		storageObj.token,
    );
}
export function saveSummary(params){  //保存月度汇总
    return getRequest(
        'post',
        '/wx/summary/save',
        params,
		storageObj.token,
    );
}
/**
总体情况
**/
//
export function getByLevel(params){  //根据level获取总体情况
    return getRequest(
        'post',
        '/wx/overall/getByLevel',
        params,
		storageObj.token,
    );
}
export function saveOverall(params){  //保存总体情况
    return getRequest(
        'post',
        '/wx/overall/save',
        params,
		storageObj.token,
    );
}
/**
 拆迁情况
**/
export function getDemolition(params){
    return getRequest(
        'post',
        '/wx/demolition/get',
        params,
		storageObj.token,
    );
}
export function saveDemolition(params){
    return getRequest(
        'post',
        '/wx/demolition/save',
        params,
		storageObj.token,
    );
}
